package com.edu.dao.impl;/*
 * @Author:liwentao
 * @Date:2025/9/19-09-19-11:48
 */

import com.edu.dao.BaseDao;
import com.edu.dao.userDao;
import com.edu.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class userDaoImpl implements userDao {
    @Override
    public User sqlUserLogIn(User u) {
        User logInUser = null;
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "SELECT * FROM admin WHERE username = ? and password = ?";
        try{
            conn = BaseDao.getConn();
            ps = conn.prepareStatement(sql);
            ps.setString(1,u.getUsername());
            ps.setString(2,u.getPassword());
            rs = ps.executeQuery();
            while(rs.next()){
                logInUser = new User();
                logInUser.setUsername(rs.getString(1));
                logInUser.setPassword(rs.getString(2));
                return logInUser;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.closeAll(conn,ps,rs);
        }
        return null;
    }
}
